package com.lboyang.controller;

import com.lboyang.entity.Payment;
import com.lboyang.entity.common.ApiResult;
import com.lboyang.service.PaymentService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

/**
 * @Description:
 * @Author: Aiguodala
 * @CreateDate: 2021/4/24 17:04
 */

@RestController
@Slf4j
public class PaymentController {

    @Autowired
    private PaymentService paymentService;

    @Value("${server.port}")
    private String serverPort;

    @ApiOperation(value = "插入订单")
    @PostMapping("/payment/save")
    public ApiResult save(@RequestBody Payment payment) {
        int save = paymentService.save(payment);
        log.info("****插入结果"+save);
        if (save > 0) {
            return ApiResult.success("插入成功 "+serverPort);
        }

        return ApiResult.failed("插入失败 " + serverPort);
    }

    @GetMapping("/payment/get/{id}")
    public ApiResult getById(@PathVariable("id") Long id) {
        Payment payment = paymentService.getById(id);

        if (payment == null) {
            return ApiResult.failed("查询失败 " + serverPort);
        }
        return ApiResult.success(payment,"查询成功 " + serverPort);


    }
}
